package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hulk.ratel.common.constant.enums.ArchivedFlag;
import com.hulk.ratel.common.constant.enums.AuditedFlag;
import com.hulk.ratel.common.constant.enums.UseFlag;
import com.hulk.ratel.persistence.entity.TxncodeOrgClazz;
import com.hulk.ratel.persistence.repository.ITxncodeOrgClazzRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by hulk on 2017/11/22.
 * 交易支付机构配置类参数
 */
@Slf4j
@Component
public class TxnCodeOrgClazzCahce {

    @Autowired
    private ITxncodeOrgClazzRepository txncodeOrgClazzRepository;

    /**
     * 交易支付机构配置类
     *
     * @param workId
     * @param orgCode
     * @param txnCode
     * @return
     */
    @Cached( key = "#orgCode +#txnCode + 'TxnCodePayOrgClazzCahce_findTxnCodePayOrgClazz'", cacheType = CacheType.LOCAL ,expire =600 )
    public TxncodeOrgClazz findTxnCodePayOrgClazz(String workId, String orgCode, String txnCode) {
        TxncodeOrgClazz bean = new TxncodeOrgClazz();
        bean.setOrgCode(orgCode);
        bean.setTxnCode(txnCode);
        bean.setArchivedFlag(ArchivedFlag.N.getValue());
        bean.setAuditedFlag(AuditedFlag.Y.getValue());
        bean.setUseFlag(UseFlag.Y.getValue());
        Wrapper<TxncodeOrgClazz> query = new QueryWrapper<>(bean);
        return txncodeOrgClazzRepository.getOne(query);
    }
}
